//
//  ZZCGreatTableViewCell.m
//  B段项目
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "ZZCGreatTableViewCell.h"

@implementation ZZCGreatTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}


-(void)createSubView{
    
    
    //图片
    self.goodImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:self.goodImageView];
    [self.goodImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.mas_equalTo(20);
        make.width.mas_equalTo(WIDTH - 40);
        make.height.mas_equalTo(HEIGHT / 3);
    }];
    
    
    //标题
    self.titleLb = [[UILabel alloc]init];
    self.titleLb.font = [UIFont boldSystemFontOfSize:18];
    [self.contentView addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(20);
        make.top.equalTo(self.goodImageView.mas_bottom).offset(30);
        make.width.equalTo(self.goodImageView.mas_width).offset(-100);
        make.height.mas_equalTo(30);
    }];
    
    
    //立即购买按钮
    self.shopButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.shopButton.layer.masksToBounds = YES;
    self.shopButton.layer.cornerRadius = 15;
    self.shopButton.backgroundColor = [UIColor colorWithRed:0.47 green:0.71 blue:0.27 alpha:1];
    [self.shopButton setTitle:@"立即购买" forState:UIControlStateNormal];
    //设置字体大小
    self.shopButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.shopButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.contentView addSubview:self.shopButton];
    [self.shopButton addTarget:self action:@selector(shopButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.shopButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.titleLb.mas_right).offset(15);
        make.top.equalTo(self.titleLb.mas_top);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    
}

-(void)setGreatPro:(ZZCGreatModel *)greatPro{
    _greatPro = greatPro;

    self.titleLb.text = self.greatPro.title;
    [self.goodImageView sd_setImageWithURL:self.greatPro.coverimg placeholderImage:PLACEHOLDER_IMAGE];
    
}

-(void)shopButton:(UIButton *)btn{
    
    [self.goodProDeleage setDataToController:[NSURL URLWithString:self.greatPro.buyurl]];
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
